package com.zzw.controller;

import com.zzw.entity.InStore;
import com.zzw.entity.Result;
import com.zzw.entity.Store;
import com.zzw.page.Page;
import com.zzw.service.InStoreService;
import com.zzw.service.StoreService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Project: warehouse
 * @Description:
 * @Author: zzw
 */
@RestController
@RequestMapping("/inStore")
@Slf4j
@Api(tags = "入库模块")
public class InStoreController {

    @Autowired
    private StoreService storeService;

    @Autowired
    private InStoreService inStoreService;


    /**
     * 查询所有仓库的url接口
     */
    @GetMapping("/store-list")
    public Result storeList() {
        //执行业务
        List<Store> storeList = storeService.queryAllStore();
        //响应
        return Result.ok(storeList);
    }

    /**
     * 添加入库单
     *
     * @param inStore
     * @param buyId
     * @return
     */
    @PostMapping
    @ApiOperation("添加入库单")
    public Result saveInStore(@RequestBody InStore inStore, Integer buyId) {
        return inStoreService.saveInStore(inStore, buyId);
    }

    /**
     * 分页查询入库单
     *
     * @param page
     * @param inStore
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("分页查询入库单")
    public Result inStorePageList(Page page, InStore inStore) {
        Page page1 = inStoreService.queryInStorePage(page, inStore);
        return Result.ok(page1);
    }

    /**
     * 确认入库单的url接口
     *
     * @param inStore
     * @return
     */
    @PutMapping("/confirm")
    @ApiOperation("确认入库单")
    public Result confirmInStore(@RequestBody InStore inStore) {
        return inStoreService.confirmInStore(inStore);
    }

    /**
     * 导出数据
     *
     * @param page
     * @param inStore
     * @return
     */
    @GetMapping("/exportTable")
    public Result exportTable(Page page, InStore inStore) {
        page = inStoreService.queryInStorePage(page, inStore);
        List<?> resultList = page.getResultList();
        //响应
        return Result.ok(resultList);
    }
}
